import axios from "axios";
import { API_URL } from "@/config/api.config";

// create an axios instance
const service = axios.create({
  // baseURL: "/api",
  baseURL: API_URL,
  timeout: 5000,
});

// request interceptor 请求拦截
service.interceptors.request.use(
  config => {
    return config;
  },
  error => {
    // Do something with request error
    // window.console.log(error,"request error");
    // for debug
    return Promise.reject(error);
  }
);

// response interceptor 响应拦截
service.interceptors.response.use(
  response => {
    // return response
    const res = response.data;
    return res;
  },
  error => {
    // for debug
    // console.log(error,'resoponse error');
    return Promise.reject(error);
  }
);

export default service;
